﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using Microsoft.Reporting.WebForms;

namespace TestAuditModel
{
    public partial class ReportForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnGo_Click(object sender, EventArgs e)
        {
            //        AuditDBConnectionString
    //        SqlDbProxy.ConnectionString = System.Configuration.ConfigurationManager.
    //ConnectionStrings["AuditDBConnectionString"].ConnectionString; 

    //        SqlDbProxy db= new SqlDbProxy("GetScores");
    //        db.AddParameter("@AnnualEventID", "PY2012");
    //        DataSet ds = db.GetDataSet();
    //        //reportViewer1.ProcessingMode = ProcessingMode.Local;

    //        ds.DataSetName = "DataSet1";
    //        ReportDataSource rds = new ReportDataSource("DataSet1", ds.Tables[0]);

    //        ReportViewer1.LocalReport.DataSources.Clear();
    //        ReportViewer1.LocalReport.ReportPath = "Report1.rdlc";//"D:\\ParticipantDetailsReport.rdlc";// @"D:/Census.rdl";
    //        ReportViewer1.LocalReport.DataSources.Add(rds);
    //        ReportViewer1.LocalReport.Refresh();

    //        db.Close();
            //  1. Clear Report Data
            ReportViewer1.LocalReport.DataSources.Clear();

            //  2. Get Connection String from Web.Config
            SqlDbProxy.ConnectionString = System.Configuration.ConfigurationManager.
            ConnectionStrings["AuditDBConnectionString"].ConnectionString; 

            //  3. Create DataSets (In my case I use 2 DataSets,
            //     you can use one or more)
            //DataSet dsHeader = new DataSet();
            //DataSet dsDetail = new DataSet();
            DataSet ds;// = new DataSet();


            //  4. Select the DataSource to both DataSets
            // (In my case both SQL Stored Procedures
            //   use the same Sql parameter)

            //SqlParameter sqlParm = new SqlParameter("@intNr",
            //                                        lineNr.ToString());
            //dsHeader = SqlHelper.ExecuteDataset(sqlCon,
            //           CommandType.StoredProcedure,
            //           "stp_S_LoadHeaderData", sqlParm);
            //dsDetail = SqlHelper.ExecuteDataset(sqlCon,
            //           CommandType.StoredProcedure,
            //           "stp_S_LoadDetailData", sqlParm);
            SqlDbProxy db = new SqlDbProxy("GetScores");
            db.AddParameter("@AnnualEventID", "PY2012");
            db.AddParameter("@SubjectID", 6);
            ds = db.GetDataSet();

            //  5. The next lines mean that you will fill the datasets
            //     with the data retrieved from the stored procedures.
            //     I had on my SQL database, giving a input parameter
            //     sqlParam as you can see before
            //     Create datasource to the report - this way you associate
            //     these local datasets to your project datasets,
            //     with the correctly loaded data
            //     Notice that DS1_stp_s_LoadHeaderData and
            //     DS1_stp_s_LoadDetailData are my Report DataSets,
            //     so you can Map the local Datasets to the report datasets

            //ReportDataSource reportDSHeader =
            //  new ReportDataSource("DS1_stp_s_LoadHeaderData",
            //                       dsHeader.Tables[0]);
            //ReportDataSource reportDSDetail =
            //  new ReportDataSource("DS1_stp_s_LoadDetailData",
            //                       dsDetail.Tables[0]);
            ReportDataSource reportDS = new ReportDataSource("DataSet1", ds.Tables[0]);

            //  6. Add these DataSources to your ReportViewer, et voilá!

            //ReportViewer1.LocalReport.DataSources.Add(reportDSHeader);
            //ReportViewer1.LocalReport.DataSources.Add(reportDSDetail);
            ReportViewer1.LocalReport.DataSources.Add(reportDS);

            ReportViewer1.LocalReport.Refresh();
            ReportViewer1.Visible = true;

        }
    }
}